<#include "/java_copyright.include">
<#assign className = table.className>
<#assign classNameLower = className?uncap_first>
package ${basepackage}.${namespace}.service;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.beans.BeanUtils;
import com.cyou.fz.commons.mybatis.selecterplus.mybatis.bean.Query;
import com.fj.hiwetop.base.BaseService;
import com.fj.hiwetop.exception.BusinessException;
import com.fj.hiwetoptools.system.UUIDUtil;

import ${basepackage}.${namespace}.pojo.${className};
import ${basepackage}.${namespace}.dao.${className}DAO;


/**
 * 
 * @Description: 业务层接口

 * @author: ???
 */
@Service("${classNameLower}Service")
public class ${className}Service extends BaseService<${className}> {
	
	@Autowired
	private ${className}DAO ${classNameLower}DAO;
	
	/**
	 *　新增，更新实体
	 */
	public void saveOrUpdate${className}(${className} ${classNameLower}) throws BusinessException{
		
		long curr = System.currentTimeMillis();

		if (StringUtils.isBlank(${classNameLower}.get${table.pkColumn.columnName}())) {
			${classNameLower}.set${table.pkColumn.columnName}(UUIDUtil.getUUID());
			${classNameLower}.setCreateTime(curr);
			${classNameLower}.setUpdateTime(curr);
			this.insert(${classNameLower});
		} else {
			${className} updateObj = get(${classNameLower}.get${table.pkColumn.columnName}());
			BeanUtils.copyProperties(${classNameLower}, updateObj, new String[] { "${table.pkColumn.columnNameLower}", "createTime","createIdStr" ,"updateTime","updateIdStr"});

			${classNameLower}.setUpdateTime(curr);
			//写入需要更新的操作者
			${classNameLower}.setUpdateIdStr("");

			this.update(${classNameLower});
		}
	}
	
}
